package com.dy.system.controller;


import com.dy.basic.util.AjaxResult;
import com.dy.basic.util.PageList;
import com.dy.system.anno.LogAnno;
import com.dy.system.domain.SystemDictionaryDetail;
import com.dy.system.query.SystemDetailQuery;
import com.dy.system.service.SystemDetailService;
import com.dy.system.service.SystemTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sysdetail")
public class SysDetailController {

    @Autowired
    private SystemTypeService systemTypeService;
    
    @Autowired
    private SystemDetailService systemDetailService;

    /**
     * 通过id查询相关的字典明细的信息
     */
    @GetMapping("/findEmp/{id}")
    public List<SystemDictionaryDetail> findBySysType(@PathVariable("id") Long id){
        return systemTypeService.findBySysType(id);
    }

    /**
     * 查询所有的信息
     */
    @GetMapping
    public List<SystemDictionaryDetail> findAll(){
        return systemDetailService.findAll();
    }

    /**
     * 修改或者添加
     */
    @PutMapping
    @LogAnno(des = "这是修改或者删除的方法!!")
    public AjaxResult UpOrAdd(@RequestBody SystemDictionaryDetail systemDictionaryDetail){
        if (systemDictionaryDetail.getId() == null){
            systemDetailService.add(systemDictionaryDetail);
        } else {
            systemDetailService.update(systemDictionaryDetail);
        }
        return AjaxResult.me().success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        systemDetailService.delete(id);
        return AjaxResult.me().success();
    }

    /**
     * 批量删除
     */
    @PatchMapping
    public AjaxResult deleteAll(@RequestBody List<Long> ids){
        systemDetailService.deleteAll(ids);
        return AjaxResult.me().success();
    }

    /**
     * 分页查询
     */
    @PostMapping
    public PageList<SystemDictionaryDetail> queryByPage(@RequestBody SystemDetailQuery query){
        PageList<SystemDictionaryDetail> systemDictionaryDetailPageList = systemDetailService.queryByPage(query);
        return systemDictionaryDetailPageList;
    }
    
}
